#!/bin/sh
#
# This is the script for generating files for a specific Dalton test job.
#
# For the .check file ksh or bash is preferred, otherwise use sh
# (and hope it is not the old Bourne shell, which will not work)
#
if [ -x /bin/ksh ]; then
   CHECK_SHELL='#!/bin/ksh'
elif [ -x /bin/bash ]; then
   CHECK_SHELL='#!/bin/bash'
else
   CHECK_SHELL='#!/bin/sh'
fi


#######################################################################
#  TEST DESCRIPTION
#######################################################################
cat > cc_rsp_twophot2.info <<'%EOF%'
   cc_rsp_twophot2
   ---------------
   Molecule:         HF in C2v
   Wave Function:    CCS, CC2, CCSD / 6-31G**
   Test Purpose:     Twophoton transition moments
%EOF%

#######################################################################
#  INTEGRAL INPUT
#######################################################################
cat > cc_rsp_twophot2.mol <<'%EOF%'
BASIS
6-31G**
Hydrogen flourid
small test basis
    2    2  Y  X      1.00D-15
        9.0   1    
F     0.0000000000000000  0.0000000000000000 1.76320000000000000      
        1.0   1
H     0.0000000000000000  0.0000000000000000 0.00000000000000000      
%EOF%

#######################################################################
#  DALTON INPUT
#######################################################################
cat > cc_rsp_twophot2.dal <<'%EOF%'
**DALTON INPUT
.RUN WAVE FUNCTIONS
**INTEGRAL
.DIPLEN
**WAVE FUNCTIONS
.CC
*SCF INPUT 
.THRESH
 1.0d-12
*CC INPUT 
.CCS
.CC2
.CCSD
.NSYM
 4
.THRENR
 1.0d-9
.THRLEQ
 1.0d-9
*CCEXCI
.NCCEXCI
 0 0 0 1
.THREXC
 1.0d-8
*CCTPA
.SELSTA
 4 1 0.0
.OPERATOR
YDIPLEN XDIPLEN 
XDIPLEN YDIPLEN 
**END OF DALTON INPUT
%EOF%
#######################################################################

 

#######################################################################

#######################################################################
#  CHECK SCRIPT
#######################################################################
echo $CHECK_SHELL >cc_rsp_twophot2.check
cat >>cc_rsp_twophot2.check <<'%EOF%'
log=$1

if [ `uname` = Linux ]; then
   GREP="egrep -a"
else
   GREP="egrep"
fi

if $GREP -q "not implemented for parallel calculations" $log; then
   echo "TEST ENDED AS EXPECTED"
   exit 0
fi

# SCF, MP2, CC2, and CCSD energies:
CRIT1=`$GREP "Final * HF energy:" $log | $GREP "\-100.008919(8|9)." | wc -l`
CRIT2=`$GREP "Total MP2 * energy: * \-100.193662(5|6)." $log | wc -l`
CRIT3=`$GREP "Total CC2 * energy: * \-100.194686(8|9)." $log | wc -l`
CRIT4=`$GREP "Total CCSD * energy: * \-100.1977909." $log | wc -l`
TEST[1]=`expr $CRIT1 \+ $CRIT2 \+ $CRIT3 \+ $CRIT4`
CTRL[1]=7
ERROR[1]="ENERGIES NOT CORRECT"


# CCS twophoton transition moment:
#  +-------------------+----------------+----------------+----------------+
#  |    A        B     | M_0f(  0.0000) | M_f0(  0.0000) | S^0f(  0.0000) |
#  +-------------------+----------------+----------------+----------------+
#  | YDIPLEN  XDIPLEN  |     0.36465397 |     0.14365998 |     0.05238618 |
#  | XDIPLEN  YDIPLEN  |    -0.36465397 |    -0.14365998 |     0.05238618 |
#  +-------------------+----------------+----------------+----------------+
CRIT1=`$GREP "YDIPLEN *XDIPLEN *. *( |0|\-|\-0)\.364653.. *. *(0| |\-0|\-)\.143659.. *. *(0| )\.052386.." $log | wc -l`
CRIT2=`$GREP "XDIPLEN *YDIPLEN *. *( |0|\-|\-0)\.364653.. *. *(0| |\-0|\-)\.143659.. *. *(0| )\.052386.." $log | wc -l`
TEST[2]=`expr $CRIT1 \+ $CRIT2`
CTRL[2]=2
ERROR[2]="CCS TWOPHOTON TRANSITION MOMENTS OR STRENGTHS NOT CORRECT"



# CC2 twophoton transition moment:
#  +-------------------+----------------+----------------+----------------+
#  |    A        B     | M_0f(  0.0000) | M_f0(  0.0000) | S^0f(  0.0000) |
#  +-------------------+----------------+----------------+----------------+
#  | YDIPLEN  XDIPLEN  |     0.81547843 |     0.41404819 |     0.33764737 |
#  | XDIPLEN  YDIPLEN  |     0.81547843 |     0.41404819 |     0.33764737 |
#  +-------------------+----------------+----------------+----------------+
CRIT1=`$GREP "YDIPLEN *XDIPLEN *. *(0| |\-0|\-)\.81547(8|9).. *. *(0| |\-0|\-)\.414048.. *. *(0| )\.33764(7|8).." $log | wc -l`
CRIT2=`$GREP "XDIPLEN *YDIPLEN *. *(0| |\-0|\-)\.81547(8|9).. *. *(0| |\-0|\-)\.414048.. *. *(0| )\.33764(7|8).." $log | wc -l`
TEST[3]=`expr $CRIT1 \+ $CRIT2`
CTRL[3]=2
ERROR[3]="CC2 TWOPHOTON TRANSITION MOMENTS OR STRENGTHS NOT CORRECT"



# CCSD twophoton transition moment:
#  +-------------------+----------------+----------------+----------------+
#  |    A        B     | M_0f(  0.0000) | M_f0(  0.0000) | S^0f(  0.0000) |
#  +-------------------+----------------+----------------+----------------+
#  | YDIPLEN  XDIPLEN  |    -0.16802885 |    -0.04758689 |     0.00799597 |
#  | XDIPLEN  YDIPLEN  |    -0.16802885 |    -0.04758689 |     0.00799597 |
#  +-------------------+----------------+----------------+----------------+
CRIT1=`$GREP "YDIPLEN *XDIPLEN *. *(0| |\-0|\-)\.168028.. *. *(0| |\-0|\-)\.047586.. *. *(0| )\.007995.." $log | wc -l`
CRIT2=`$GREP "XDIPLEN *YDIPLEN *. *(0| |\-0|\-)\.168028.. *. *(0| |\-0|\-)\.047586.. *. *(0| )\.007995.." $log | wc -l`
TEST[4]=`expr $CRIT1 \+ $CRIT2`
CTRL[4]=2
ERROR[4]="CCSD TWOPHOTON TRANSITION MOMENTS NOT CORRECT"

# CCS/CC2/CCSD excitation energies
CRIT1=`$GREP "\^1A2  \|    1   \|     1\.455144.  \|      39\.596..  \|    319367\....  \| 100\.00" $log | wc -l`
CRIT2=`$GREP "\^1A2  \|    1   \|     1\.518329.  \|      41\.315..  \|    333234\....  \|  99\.13" $log | wc -l`
CRIT3=`$GREP "\^1A2  \|    1   \|     1\.328216.  \|      36\.142..  \|    291509\....  \|   ( |0)\.35" $log | wc -l`
TEST[5]=`expr $CRIT1 \+ $CRIT2 \+ $CRIT3`
CTRL[5]=3
ERROR[5]="CC EXCITATION ENERGIES NOT CORRECT"


PASSED=1
for i in 1 2 3 4 5
do
   if [ ${TEST[i]} -ne ${CTRL[i]} ]; then
     echo "${ERROR[i]} ( test = ${TEST[i]}; control = ${CTRL[i]} ); "
     PASSED=0
   fi
done

if [ $PASSED -eq 1 ]
then
  echo TEST ENDED PROPERLY
  exit 0
else
  echo THERE IS A PROBLEM
  exit 1
fi                
%EOF%
#######################################################################
